//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "CTSMMCapletCalibration.h"
using namespace Cephei::QL::Models::Marketmodels::Models;
#include <gen/QL/Models/Marketmodels/EvolutionDescription.h>
#include <gen/QL/Models/Marketmodels/PiecewiseConstantCorrelation.h>
#include <gen/QL/Models/Marketmodels/Models/PiecewiseConstantVariance.h>
#include <gen/QL/Models/Marketmodels/CurveState.h>
#include <gen/QL/Math/Matrix.h>
using namespace Cephei::QL::Models::Marketmodels;
using namespace Cephei::QL::Math;
#undef HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::CCTSMMCapletCalibration (boost::shared_ptr<QuantLib::CTSMMCapletCalibration>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCTSMMCapletCalibration = NULL;
#endif
	_ppCTSMMCapletCalibration = &childNative;
    
}
Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::CCTSMMCapletCalibration (QuantLib::CTSMMCapletCalibration& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phCTSMMCapletCalibration = NULL;
#endif
	_ppCTSMMCapletCalibration = new boost::shared_ptr<QuantLib::CTSMMCapletCalibration> (&childNative);
    
    _CTSMMCapletCalibrationOwner = owner;
    
}

Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::CCTSMMCapletCalibration (CCTSMMCapletCalibration^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCTSMMCapletCalibration = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppCTSMMCapletCalibration = new boost::shared_ptr<QuantLib::CTSMMCapletCalibration> (copy->GetShared());
        
    }
}
Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::CCTSMMCapletCalibration (PLATFORM::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCTSMMCapletCalibration = NULL;
#endif
	if (!t->IsSubclassOf(CCTSMMCapletCalibration::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::CCTSMMCapletCalibration (QuantLib::Handle<QuantLib::CTSMMCapletCalibration>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phCTSMMCapletCalibration = &childNative;
	_ppCTSMMCapletCalibration = &static_cast<boost::shared_ptr<QuantLib::CTSMMCapletCalibration>>(childNative.currentLink());
    
    _CTSMMCapletCalibrationOwner = owner;
}
Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::CCTSMMCapletCalibration (QuantLib::Handle<QuantLib::CTSMMCapletCalibration> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phCTSMMCapletCalibration = &childNative;
	_ppCTSMMCapletCalibration = &static_cast<boost::shared_ptr<QuantLib::CTSMMCapletCalibration>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::CCTSMMCapletCalibration (QuantLib::CTSMMCapletCalibration childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCTSMMCapletCalibration = NULL;
#endif
	_ppCTSMMCapletCalibration = new boost::shared_ptr<QuantLib::CTSMMCapletCalibration> (new QuantLib::CTSMMCapletCalibration (childNative));
    
}
#endif

Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::~CCTSMMCapletCalibration ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppCTSMMCapletCalibration != NULL)
    {
	    delete _ppCTSMMCapletCalibration;
        _ppCTSMMCapletCalibration = NULL;
    }
}
Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::!CCTSMMCapletCalibration ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppCTSMMCapletCalibration != NULL)
    {
	    delete _ppCTSMMCapletCalibration;
    }
}
QuantLib::CTSMMCapletCalibration& Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::GetReference ()
{
    if (_ppCTSMMCapletCalibration == NULL) throw REFNEW NativeNullException ();
	return **_ppCTSMMCapletCalibration;
}
boost::shared_ptr<QuantLib::CTSMMCapletCalibration>& Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::GetShared ()
{
    if (_ppCTSMMCapletCalibration == NULL) throw REFNEW NativeNullException ();
	return *_ppCTSMMCapletCalibration;
}
QuantLib::CTSMMCapletCalibration* Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::GetPointer ()
{
    if (_ppCTSMMCapletCalibration == NULL) throw REFNEW NativeNullException ();
	return &**_ppCTSMMCapletCalibration;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::CTSMMCapletCalibration>& Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::GetHandle ()
{
	if (_phCTSMMCapletCalibration == NULL)
	{
		_phCTSMMCapletCalibration = new Handle<QuantLib::CTSMMCapletCalibration> (*_ppCTSMMCapletCalibration);
	}
	return *_phCTSMMCapletCalibration;
}
#endif
bool Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::HasNative () 
{
	return (_ppCTSMMCapletCalibration != NULL);
}

Boolean Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::Calibrate (UInt32 numberOfFactors, UInt32 maxIterations, Double tolerance, Microsoft::FSharp::Core::FSharpOption<UInt32>^ innerMaxIterations, Microsoft::FSharp::Core::FSharpOption<Double>^ innerTolerance)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Natural _numberOfFactors = (QuantLib::Natural)ValueHelper::Convert (numberOfFactors); //a
        QuantLib::Natural _maxIterations = (QuantLib::Natural)ValueHelper::Convert (maxIterations); //a
        QuantLib::Real _tolerance = (QuantLib::Real)ValueHelper::Convert (tolerance); //a
        QuantLib::Natural _innerMaxIterations = 
            (Microsoft::FSharp::Core::FSharpOption<UInt32>::IsSome::get (innerMaxIterations) ? (QuantLib::Natural)ValueHelper::Convert (innerMaxIterations->Value) : 100); //9a
        QuantLib::Real _innerTolerance = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (innerTolerance) ? (QuantLib::Real)ValueHelper::Convert (innerTolerance->Value) : 1e-8); //9a
    	bool _rv = (bool)(*_ppCTSMMCapletCalibration)->calibrate ( _numberOfFactors,  _maxIterations,  _tolerance,  _innerMaxIterations,  _innerTolerance );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::CapletMaxError::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCTSMMCapletCalibration)->capletMaxError ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::CapletRmsError::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCTSMMCapletCalibration)->capletRmsError ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Models::Marketmodels::ICurveState^ Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::CurveState::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::CurveState>& _rv = (boost::shared_ptr<QuantLib::CurveState>&)(*_ppCTSMMCapletCalibration)->curveState ( );   
        Cephei::QL::Models::Marketmodels::CCurveState^ _nrv = REFNEW Cephei::QL::Models::Marketmodels::CCurveState (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::DeformationSize::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCTSMMCapletCalibration)->deformationSize ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::Displacements::get ()
{
    try
    {
    	std::vector<QuantLib::Spread> _rv = (std::vector<QuantLib::Spread>)(*_ppCTSMMCapletCalibration)->displacements ( );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt32 Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::Failures::get ()
{
    try
    {
    	QuantLib::Natural _rv = (QuantLib::Natural)(*_ppCTSMMCapletCalibration)->failures ( );   
        UInt32 _nrv = (UInt32)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::MdlCapletVols::get ()
{
    try
    {
    	std::vector<QuantLib::Volatility>& _rv = (std::vector<QuantLib::Volatility>&)(*_ppCTSMMCapletCalibration)->mdlCapletVols ( );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::MdlSwaptionVols::get ()
{
    try
    {
    	std::vector<QuantLib::Volatility>& _rv = (std::vector<QuantLib::Volatility>&)(*_ppCTSMMCapletCalibration)->mdlSwaptionVols ( );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::MktCapletVols::get ()
{
    try
    {
    	std::vector<QuantLib::Volatility>& _rv = (std::vector<QuantLib::Volatility>&)(*_ppCTSMMCapletCalibration)->mktCapletVols ( );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::MktSwaptionVols::get ()
{
    try
    {
    	std::vector<QuantLib::Volatility>& _rv = (std::vector<QuantLib::Volatility>&)(*_ppCTSMMCapletCalibration)->mktSwaptionVols ( );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Models::Marketmodels::Models::ICTSMMCapletCalibration^ Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::PerformChecks (Cephei::QL::Models::Marketmodels::IEvolutionDescription^ evolution, Cephei::QL::Models::Marketmodels::IPiecewiseConstantCorrelation^ corr, Cephei::Core::IVector<Cephei::QL::Models::Marketmodels::Models::IPiecewiseConstantVariance^>^ displacedSwapVariances, Cephei::Core::IVector<Double>^ mktCapletVols, Cephei::QL::Models::Marketmodels::ICurveState^ cs)
{
    CEvolutionDescription^ _Cevolution;
    CPiecewiseConstantCorrelation^ _Ccorr;
    CCurveState^ _Ccs;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Cevolution = safe_cast<CEvolutionDescription^> (evolution);
        _Cevolution->Lock();
        QuantLib::EvolutionDescription& _evolution = static_cast<QuantLib::EvolutionDescription&> (_Cevolution->GetReference ()); 
        _Ccorr = safe_cast<CPiecewiseConstantCorrelation^> (corr);
        _Ccorr->Lock();
        QuantLib::PiecewiseConstantCorrelation& _corr = static_cast<QuantLib::PiecewiseConstantCorrelation&> (_Ccorr->GetReference ()); 
        displacedSwapVariances->Lock();
        INativeVector<Cephei::QL::Models::Marketmodels::Models::IPiecewiseConstantVariance^>^ _NCIdisplacedSwapVariances = displacedSwapVariances->getFeature (NativeFeature::shared_ptr);
        CPiecewiseConstantVarianceVector^ _NCdisplacedSwapVariances = safe_cast<CPiecewiseConstantVarianceVector^>(_NCIdisplacedSwapVariances);
        std::vector<boost::shared_ptr<
                        QuantLib::PiecewiseConstantVariance> >& _displacedSwapVariances = static_cast<std::vector<boost::shared_ptr<
                        QuantLib::PiecewiseConstantVariance> >&> (_NCdisplacedSwapVariances->GetShared ());
        mktCapletVols->Lock();
        INativeVector<Double>^ _NCImktCapletVols = mktCapletVols->getFeature (NativeFeature::Value);
        CDoubleVector^ _NCmktCapletVols = safe_cast<CDoubleVector^>(_NCImktCapletVols);
        std::vector<QuantLib::Volatility>& _mktCapletVols = static_cast<std::vector<QuantLib::Volatility>&> (_NCmktCapletVols->GetReference ());
        _Ccs = safe_cast<CCurveState^> (cs);
        _Ccs->Lock();
        QuantLib::CurveState& _cs = static_cast<QuantLib::CurveState&> (_Ccs->GetReference ()); 
    	(*_ppCTSMMCapletCalibration)->performChecks ( _evolution,  _corr,  _displacedSwapVariances,  _mktCapletVols,  _cs );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cevolution != nullptr) _Cevolution->Unlock();
        if (_Ccorr != nullptr) _Ccorr->Unlock();
        if (displacedSwapVariances != nullptr) displacedSwapVariances->Unlock(); //NO2  
        if (mktCapletVols != nullptr) mktCapletVols->Unlock(); //NO2  
        if (_Ccs != nullptr) _Ccs->Unlock();
    }
}
Cephei::QL::Math::IMatrix^ Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::SwapPseudoRoot (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i); //a
    	QuantLib::Matrix& _rv = (QuantLib::Matrix&)(*_ppCTSMMCapletCalibration)->swapPseudoRoot ( _i );   
        Cephei::QL::Math::CMatrix^ _nrv = REFNEW Cephei::QL::Math::CMatrix (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Cephei::QL::Math::IMatrix^>^ Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::SwapPseudoRoots::get ()
{
    try
    {
    	std::vector<QuantLib::Matrix>& _rv = (std::vector<QuantLib::Matrix>&)(*_ppCTSMMCapletCalibration)->swapPseudoRoots ( );   
        CoVector<Cephei::QL::Math::IMatrix^>^ _nrv = REFNEW CoVector<Cephei::QL::Math::IMatrix^>(REFNEW CMatrixVector (_rv, this));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::SwaptionMaxError::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCTSMMCapletCalibration)->swaptionMaxError ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::SwaptionRmsError::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppCTSMMCapletCalibration)->swaptionRmsError ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::TimeDependentCalibratedSwaptionVols (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i); //a
    	std::vector<QuantLib::Volatility>& _rv = (std::vector<QuantLib::Volatility>&)(*_ppCTSMMCapletCalibration)->timeDependentCalibratedSwaptionVols ( _i );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Models::Marketmodels::Models::CCTSMMCapletCalibration::TimeDependentUnCalibratedSwaptionVols (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i); //a
    	std::vector<QuantLib::Volatility>& _rv = (std::vector<QuantLib::Volatility>&)(*_ppCTSMMCapletCalibration)->timeDependentUnCalibratedSwaptionVols ( _i );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

